package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.TRole;
import com.dk.service.TRoleServiceI;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tRoleController")
public class TRoleController {

    @Reference
    private TRoleServiceI tRoleServiceI;

    @RequestMapping("list")
    public String listGet(){
        return "role/list";
    }
    //角色查询
    @RequestMapping("getCarAllInfo")
    @ResponseBody
    public List<TRole> getCarAllInfo(){
        List<TRole> list = tRoleServiceI.getCarAllInfo();
        return list;
    }

    //跳转增加角色
    @RequestMapping("insertInfo")
    public String insertInfo(){
        return "role/add";
    }

    //确认增加
    @RequestMapping("saveById")
    @ResponseBody
    public  int saveById(String roleName, @RequestParam("nodeIds[]")Integer[] nodeIds){
        tRoleServiceI.saveById(roleName,nodeIds);
        return 1;
    }
    //回显
    @RequestMapping("updateInfo/{roleId}")
    public String updateInfo(@PathVariable("roleId")Integer roleId, Model model){
        TRole tRole = tRoleServiceI.getUpdate(roleId);
        model.addAttribute("tRole",tRole);
        return "role/update";
    }
    //确认修改
    @RequestMapping("updateById")
    @ResponseBody
    public int updateById(TRole tRole, @RequestParam("nodeIds[]")Integer[] nodeIds){
        tRoleServiceI.updateById(tRole,nodeIds);
        return 1;
    }
    //确认删除
    @RequestMapping("deleteById/{roleId}")
    @ResponseBody
    public int deleteById(@PathVariable("roleId")Integer roleId){
        tRoleServiceI.deleteById(roleId);
        return 1;
    }
}
